package com.wc.算法基础课.A第一讲基础算法.前缀和与差分.空调;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/2 11:29
 * 思路：A - B数组进行差分，差分的本质是修改两个数的值，我们将差分的值全变成0就相当于原来题目中的解，也就是Math.max(pos,neg);
 * @description https://www.acwing.com/problem/content/4265/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    // 原数组
    static int[] t = new int[N];
    // 要变得数组
    static int[] p = new int[N];
    static int[] d = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            t[i] = sc.nextInt();
        }
        long pos = 0, neg = 0;
        for (int i = 1; i <= n; i++) {
            p[i] = sc.nextInt();
            add(i, p[i] - t[i]);
            if (d[i] > 0) pos += d[i];
            else neg -= d[i];
        }
        out.println(Math.max(pos, neg));
        out.flush();
    }

    static void add(int i, int c) {
        d[i] += c;
        d[i + 1] -= c;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
